<template>
  <div id="examinpaper_data_detail_container" class="container">
    <div class="content">
      <el-breadcrumb separator-class="el-icon-arrow-right" v-if="!hideHead">
        <el-breadcrumb-item
          class="title"
          style=" font-size: 0.2rem;cursor: pointer;"
          @click.native="hide"
        >测评数据</el-breadcrumb-item>
        <el-breadcrumb-item class="title" style=" font-size: 0.2rem;">查看详情</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="preview">
        <div class="preview_info">
          <div class="info_title">{{previewData.title}}</div>
          <div class="info_left">
            <!-- <div>测评等级：初级</div> -->
            <div>
              <span>姓名：{{studentInfo.studentName}}</span>
              <span>手机号：{{studentInfo.phoneNo}}</span>
              <!-- <span class="label">等级：{{studentInfo._paperLevel}}</span> -->
              <span>适用年龄：{{previewData.ageStart}}-{{previewData.ageEnd}}岁</span>
            </div>
          </div>
          <div class="info_right">
            得分：
            <span>{{realScore}}/</span>
            <label>{{totalScore}}</label>
          </div>

          <!-- <div class="preview_title">
            <span class="title">{{previewData.title}}</span>
            <div style="margin:0.2rem 0.1rem;">
              <span class="label">姓名：{{studentInfo.studentName}}</span>
              <span class="label">手机号：{{studentInfo.phoneNo}}</span>
              
              <span class="label">适用年龄：{{previewData.ageStart}}-{{previewData.ageEnd}}岁</span>
            </div>
          </div>
          <div class="preview_mark">
            得分：
            <span>{{realScore}}</span>/
            <span>{{totalScore}}</span>
          </div>-->
        </div>
        <audio ref="audio" :src="audioUrl"></audio>
        <div>
          <div class="preview_subject" v-for="(item,index) in previewData.evSubjects" :key="index">
            <div class="subject_title">
              <div class="subject_title_left">{{index+1}}.{{item.title}}</div>
              <div class="subject_title_right">
                <div class="title_score">
                  得分：
                  <span style="color:red;">{{item._realScore}}</span>/
                  <span>{{item.score}}</span>
                  分
                </div>
              </div>
            </div>
            <div class="test_stem" v-html="item.content"></div>
            <div v-for="sound in item.fileList" class="soundPlay">
              <el-image
                style="width: 0.2rem; height: 0.14rem;margin-right:0.06rem;"
                :src="require('@/assets/img/common/audio.png')"
                fit="cover"
              ></el-image>
              <div class="soundName">{{sound.name}}</div>
              <el-image
                v-if="!sound.isPlay"
                style="width: 0.22rem; height: 0.22rem;cursor: pointer;margin-left:0.1rem;"
                :src="require('@/assets/img/common/play.png')"
                @click="play(sound)"
                fit="cover"
              ></el-image>
              <el-image
                v-if="sound.isPlay"
                style="width: 0.22rem; height: 0.22rem;cursor: pointer;margin-left:0.1rem;"
                :src="require('@/assets/img/common/suspend.png')"
                @click="pause(sound)"
                fit="cover"
              ></el-image>
            </div>
            <div class="subject_question" v-for="(question,index) in item.questions" :key="index">
              <div class="question_title">
                <div class="index">
                  <div class="num" v-if="index<10">{{'0'+(index+1)}}</div>
                  <div class="num" v-else>{{index+1}}</div>
                </div>
                <div>
                  <div class="title_name" v-if="question.title !=''">{{question.title}}</div>
                  <div v-for="sound in question.fileList" class="soundPlay">
                    <el-image
                      style="width: 0.2rem; height: 0.14rem;margin-right:0.06rem;"
                      :src="require('@/assets/img/common/audio.png')"
                      fit="cover"
                    ></el-image>
                    <div class="soundName">{{sound.name}}</div>
                    <el-image
                      v-if="!sound.isPlay"
                      style="width: 0.22rem; height: 0.22rem;cursor: pointer;margin-left:0.1rem;"
                      :src="require('@/assets/img/common/play.png')"
                      @click="play(sound)"
                      fit="cover"
                    ></el-image>
                    <el-image
                      v-if="sound.isPlay"
                      style="width: 0.22rem; height: 0.22rem;cursor: pointer;margin-left:0.1rem;"
                      :src="require('@/assets/img/common/suspend.png')"
                      @click="pause(sound)"
                      fit="cover"
                    ></el-image>
                  </div>
                </div>
                <!-- <div class="title_name">{{question.title}}</div>
              <el-image
                v-if="question.sound !=''"
                style="width: 0.28rem; height: 0.22rem;cursor: pointer;margin-bottom:0.04rem;margin-right:0.1rem;"
                :src="require('@/assets/img/common/audio.png')"
                fit="cover"
              ></el-image>
              <el-image
                v-if="question.sound !='' && !question.isPlay"
                style="width: 0.3rem; height: 0.3rem;cursor: pointer;margin-right:0.1rem;"
                :src="require('@/assets/img/common/play.png')"
                @click="play(question)"
                fit="cover"
              ></el-image>
              <el-image
                v-if="question.sound !='' && question.isPlay"
                style="width: 0.3rem; height: 0.3rem;cursor: pointer;"
                :src="require('@/assets/img/common/suspend.png')"
                @click="pause(question)"
                fit="cover"
                ></el-image>-->
                <!-- <el-button type="danger" v-if="question.sound !=''" @click="play(question)">播放按钮</el-button> -->

                <span class="question_code">
                  <i
                    v-if="question.studentInfo&&question.studentInfo.isCorrect==1"
                    class="el-icon-success"
                    style="color:#67C23A;"
                  ></i>
                  <i
                    v-else-if="question.studentInfo&&question.studentInfo.isCorrect==0"
                    class="el-icon-error"
                    style="color:#E6A23C;"
                  ></i>
                  <span
                    style="color:red;"
                    v-if="question.studentInfo"
                  >+{{question.studentInfo.studentScore||0}}</span>
                  <span style="color:red;" v-else>+0</span>
                </span>
              </div>
              <div class="answers" v-if="question.type == 1">
                <div>
                  <div
                    class="answers_title"
                    v-for="answer,index2 in question.answers"
                  >{{charCode[index2]}}.&nbsp;{{answer.title}}</div>
                </div>
                <!-- <div v-else>
                  <span     v-if="checkHasFeed(question.answers)"
                    v-for="answer,index2 in question.answers"
                    class="answers_title"
                  >{{charCode[index2]}}.{{answer.title}}</span>
                </div>-->
                <!-- <span
                v-for="(answer,index2) in question.answers"
                class="answers_title" :key="index2"
                >{{charCode[index2]}}.{{answer.title}}</span>-->
              </div>
              <div class="right_answer" v-if="question.type == 1">
                选择答案：
                <span>{{getSelectKey(question,question.studentInfo)}}</span>
                <span style="margin:0 0.2rem;"></span>
                <template v-if="question.studentInfo&&question.studentInfo.isCorrect==0">
                  正确答案：
                  <span style="color:#ea9a10">{{getRightKey(question)}}</span>
                </template>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
var vm, $audio;
export default {
  components: {},
  data: function() {
    return {
      previewData: {},
      charCode: [],
      audioUrl: "",
      /**实际得分 */
      realScore: 0,
      currentPlayData: {},
      /**试卷总分 */
      totalScore: 0,
      toPath: "",
      paperId: "",
      studentInfo: {},
      hideHead: false
    };
  },
  methods: {
    /**校验选项是否换行 */
    checkHasFeed(list) {
      let a = false;
      list.forEach(item => {
        if (item.title.length > 2) {
          a = true;
        }
      });
      return a;
    },
    hide() {
      this.$emit("hide");
    },
    /**返回选择答案 */
    getSelectKey(question, stu) {
      let str = "";
      if (question.answers && stu) {
        question.answers.forEach((item, index) => {
          if (item.title == stu.studentContent) {
            str = vm.charCode[index];
          }
        });
      }
      return str;
    },
    /**返回正确答案 */
    getRightKey(question) {
      let str = "";
      if (question.answers != null) {
        question.answers.forEach((item, index) => {
          if (item.isCorrect == "1") {
            str = vm.charCode[index];
          }
        });
      }
      return str;
    },
    play(item) {
      if (vm.currentPlayData && vm.currentPlayData.isPlay) {
        vm.currentPlayData.isPlay = false;
        this.$refs.audio.pause();
      }
      item.isPlay = true;
      if (
        vm.currentPlayData &&
        vm.currentPlayData.questionId == item.questionId
      ) {
        vm.currentPlayData.isPlay = true;
      } else {
        vm.currentPlayData = item;
        this.$refs.audio.src = item.url;
      }
      this.$refs.audio.play(); //开始播放
      this.$refs.audio.addEventListener(
        "ended",
        function() {
          vm.currentPlayData.isPlay = false;
          item.isPlay = false;
        },
        false
      );
    },
    pause(item) {
      item.isPlay = false;
      vm.currentPlayData.isPlay = false;
      this.$refs.audio.pause(); //开始播放
    },
    /**
     * 初始化
     *@param stu 学员信息对象
     *@param hideHead 是否隐藏头部面包屑，默认显示
     */
    initData(stu, hideHead = false) {
      this.studentInfo = stu;
      console.log(this.studentInfo);
      this.hideHead = hideHead;
      vm.totalScore = 0;
      vm.realScore = stu.studentScore;
      api
        .examinpaperDetailNopage({
          reportId: stu.reportId,
          paperId: stu.paperId
        })
        .then(function(data) {
          // debugger
          if (data.resultCode == 2000) {
            data.list[0].evSubjects.forEach(item => {
              vm.totalScore += item.score;
              item.fileList = [];
              if (item.sound && item.sound != "") {
                let soundArr = item.sound.split(",");
                for (let i = 0; i < soundArr.length; i++) {
                  // let
                  item.fileList.push({
                    name: soundArr[i].substring(
                      soundArr[i].lastIndexOf("/") + 1
                    ),
                    url: soundArr[i],
                    questionId: tool.uuid(),
                    isPlay: false
                  });
                }
              }
              let s = 0;
              item.questions.forEach(question => {
                question.fileList = [];
                if (question.sound && question.sound != "") {
                  let soundArr = question.sound.split(",");
                  for (let i = 0; i < soundArr.length; i++) {
                    // let
                    question.fileList.push({
                      name: soundArr[i].substring(
                        soundArr[i].lastIndexOf("/") + 1
                      ),
                      url: soundArr[i],
                      questionId: tool.uuid(),
                      isPlay: false
                    });
                  }
                }
                if (question.studentInfo) {
                  // vm.realScore+=(question.studentInfo.studentScore||0);
                  s += question.studentInfo.studentScore || 0;
                }
              });
              item._realScore = s;
            });
            vm.previewData = data.list[0];
          } else {
            vm.$message.error(data.message);
          }
        });
    }
  },
  mounted() {},
  created: function() {
    vm = this;
    vm.charCode = config.charCode;
  }
};
</script>
<style lang="scss">
#examinpaper_data_detail_container {
  padding-top: 0;
  .el-form-item__label {
    font-size: 0.16rem;

    color: #666666;
  }

  .el-checkbox__label {
    font-size: 0.16rem;
    color: #666666;
  }

  .el-breadcrumb__separator {
    color: #999999;
  }
  .el-breadcrumb__inner.is-link {
    font-weight: 300;
    color: #333333;
  }
  .el-breadcrumb__inner.is-link:hover {
    color: #3885f8;
  }
  .el-breadcrumb__item:last-child .el-breadcrumb__inner {
    color: #3885f8;
  }
  .newclassroomNumber {
    .el-input__inner {
      border-radius: 0.04rem !important;
    }
  }
  .preview {
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    font-size: 0.16rem;
    color: #666666;
    border-radius: 0.06rem;
    padding: 0.1rem 0.2rem 0.2rem 0.2rem;
    .preview_info {
      padding: 0.1rem 0 0.06rem 0;
      width: 100%;
      overflow: hidden;
      font-size: 0.16rem;
      color: #666666;
      position: relative;
      .info_title {
        text-align: center;
        font-size: 0.22rem;
        font-weight: 600;
        color: #333333;
      }
      .info_left {
        color: #333333;
        text-align: center;
        margin-top: 0.1rem;
        span {
          margin-right: 0.4rem;
        }
      }
      .info_right {
        position: absolute;
        right: 0rem;
        top: 0.4rem;
        text-align: right;
        font-size: 16px;
        width: 20%;
        label {
          font-size: 24px;
          color: #999999;
        }
        span {
          font-size: 24px;
          color: #ff4200;
        }
      }
    }
    .preview_subject {
      border: solid 1px #ebebeb;
      border-bottom: 0;
      font-size: 0.16rem;
      color: #666666;
      // border-radius: 0.04rem;
      // margin-bottom: 0.2rem;
      .subject_title {
        overflow: hidden;
        border-bottom: solid 1px #ebebeb;
        background-color: #f9fafb;
        height: 0.5rem;
        .subject_title_left {
          float: left;
          padding-top: 0.12rem;
          padding-left: 0.25rem;
          font-weight: 600;
          width: 70%;
          color: #666666;
        }
        .subject_title_right {
          float: right;
          width: 20%;
          overflow: hidden;
          text-align: center;
          .title_score {
            float: right;
            padding-top: 0.13rem;
            padding-bottom: 0.12rem;
            padding-right: 0.1rem;
            margin-right: 0.2rem;
          }
          .title_score_rightLine {
            border-right: 1px solid #f1f1f3;
          }
          .title_right_btn {
            margin-top: 0.12rem;
            float: right;
            width: 0.24rem;
            height: 0.24rem;
            cursor: pointer;
            margin-right: 0.12rem;
          }
        }
      }
      .test_stem {
        margin: 0 auto;
        width: 1093px;
        max-height: 394px;
        overflow: auto;
        color: #000000;
    font-size: 18px;
      }
      /*滚动条样式*/
      .test_stem::-webkit-scrollbar {
        width: 0.04rem;
      }
      .test_stem::-webkit-scrollbar-thumb {
        border-radius: 0.5rem;
        background: #bbbbbb;
      }
      .test_stemtest_stem::-webkit-scrollbar-track {
        background: #f2f6fc;
      }
      .soundPlay {
        display: flex;
        justify-content: center;
        align-items: center;
        color: #0e1115;
        font-size: 0.18rem;
        .soundName {
          height: 0.38rem;
          line-height: 0.38rem;
        }
      }
      .subject_question {
        .question_title {
          position: relative;
          background-color: #ddeaf8;
          // display: flex;
          // justify-content: flex-start;
          // align-items: center;
          font-size: 0.18rem;
          color: #0e1115;
          .index {
            position: absolute;
            top: 0;
            bottom: 0;
            background-color: #6d98d9;
            width: 0.68rem;
            .num {
              position: absolute;
              width: 0.68rem;
              height: 0.38rem;
              top: calc(50% - 0.19rem);
              left: 0;
              text-align: center;
              color: #fefeff;
              padding-top: 0.06rem;
              font-weight: 600;
            }
          }
          .question_code {
            position: absolute;
            top: 0.06rem;
            right: 0.1rem;
            font-size: 0.2rem;
          }
          .title_name {
            margin-left: 0.88rem;
            height: 0.38rem;
            line-height: 0.38rem;
          }
          .soundPlay {
            margin-left: 0.88rem;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            .soundName {
              height: 0.38rem;
              line-height: 0.38rem;
            }
          }
        }
        .answers {
          width: 100%;
          padding-top: 0.1rem;
          padding-left: 0.88rem;
          color: #0e1115;
          background-color: #f9fafb;
          font-size: 18px;
          .answers_title {
            padding: 0.04rem 0rem;
            cursor: pointer;
          }
        }
        .right_answer {
          background-color: #f9fafb;
          padding: 0.06rem 0.32rem 0.2rem 0.32rem;
          span {
            font-size: 0.2rem;
            color: #333333;
            margin-left: 0.1rem;
            font-weight: 500;
          }
        }
      }
    }

    .preview_subject:first-child {
      border-top-left-radius: 0.04rem;
      border-top-right-radius: 0.04rem;
    }
    .preview_subject:last-child {
      border-bottom-right-radius: 0.04rem;
      border-bottom-left-radius: 0.04rem;
      border-bottom: solid 1px #ebebeb;
    }
  }
}
</style>
<style scoped src="@/style/module/table.css"></style>
<style scoped src="@/style/clue_manage/clue_manage.css"></style>
<style scoped>
</style>
